package com.hqd.ch03.v47.boot.context.config;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

public class ConfigTreeConfigDataResource extends ConfigDataResource {

    /**
     * 配置文件路径对象
     */
    private final Path path;

    ConfigTreeConfigDataResource(String path) {
        this.path = Paths.get(path).toAbsolutePath();
    }

    ConfigTreeConfigDataResource(Path path) {
        this.path = path.toAbsolutePath();
    }

    Path getPath() {
        return this.path;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        ConfigTreeConfigDataResource other = (ConfigTreeConfigDataResource) obj;
        return Objects.equals(this.path, other.path);
    }

    @Override
    public int hashCode() {
        return this.path.hashCode();
    }

    @Override
    public String toString() {
        return "config tree [" + this.path + "]";
    }

}
